package com.bitin.adorn.modules.user.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

/**
 * @author Mr.Lu
 * @since 2024/12/12 17:50
 */
@Data
@Schema(title = "分页查询请求")
public class PagingRequest {
    /**
     * 页码
     */
    @NotNull
    @Min(value = 1)
    @Schema(title = "页码", defaultValue = "1")
    private int page;
    /**
     * 每页显示条数，默认 10
     */
    @NotNull
    @Size(min = 5, max = 500)
    @Schema(title = "每页显示条数", defaultValue = "10")
    private int size;

    public PageRequest convert(){
        return PageRequest.of(getPage() - 1, getSize());
    }

    public PageRequest convert(Sort sort){
        return PageRequest.of(getPage() - 1, getSize(), sort);
    }
}
